package cn.itcast.web.exceptions;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 统一异常处理
 */
public class CustomExceptionResolver implements HandlerExceptionResolver {
  @Override
  public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
                                       Exception ex) {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("error");
    mv.addObject("errorMsg", "对不起，我错了");
    mv.addObject("ex", ex);
    return mv;
  }
}
